



#include <iostream>
#include <vector>
using namespace std;

struct ListNode 
{
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};
 
class Solution
{
public:
    ListNode* rotateRight(ListNode* head, int k)
    {
        if (nullptr == head || nullptr == head->next || 0 == k)
            return head;

        int size = 0;
        ListNode* cur = head, * prev = nullptr;

        while (cur)
        {
            ++size;
            prev = cur;
            cur = cur->next;
        }
        k %= size;
        if (0 == k)
            return head;

        prev->next = head;
        prev = nullptr, cur = head;

        for (int i = 0; i < size - k; ++i)
        {
            prev = cur;
            cur = cur->next;
        }
        prev->next = nullptr;

        return cur;
    }

    void hanota(vector<int>& A, vector<int>& B, vector<int>& C)
    {
        return _hanota(A, B, C, A.size());
    }

private:
    void _hanota(vector<int>& a, vector<int>& b, vector<int>& c, int n)
    {
        if (1 == n)
        {
            c.push_back(a.back());
            a.pop_back();
            return;
        }

        _hanota(a, c, b, n - 1);
        c.push_back(a.back());
        a.pop_back();
        _hanota(b, a, c, n - 1);
    }
};

int main()
{

	return 0;
}